package S09.first;
import java.util.Comparator;
public class Person {
	protected String name;
	protected int age;
	public enum SortBy { //定义排序的枚举
		Name, Age;
	}
	public Person(String name, int age) {
		this.name=name;
		this.age=age;
	}
	@Override
	public String toString() {
		return name+"•"+age+"岁";
	}
	public static Comparator<Person> sortBy(SortBy sortby) { //返回比较器对象
		return (Person p1, Person p2)-> {
			if(sortby==SortBy.Name) return p1.name.compareTo(p2.name);
			return p1.age-p2.age;
		};
	}
}
